#include "../common/httplib.h"

int main()
{
    // 1. 实例化服务器对象
    httplib::Server server;
    // 2. 注册回调函数 void (const httplib::Request &,httplib::Response &)
    /*
    struct Request {
        std::string method;
        std::string path;
        Headers headers;    // Headers就相当于一个pair
        std::string body;
        Params params;
    } 
    struct Response {
        std::string version;
        int status = -1;
        std::string reason;
        Headers headers;
        std::string body;
        void set_content(const std::string &s, const std::string &content_type);    //将所有body内容设置进正文, 并设置该正文的类型是什么
        void set_header(const std::string &key, const std::string &val);
    }
    */
    server.Get("/hi", [](const httplib::Request& req, httplib::Response& rsp){
        std::cout << req.method << std::endl;
        std::cout << req.path << std::endl;
        for (auto it : req.headers) {
            std::cout << it.first << ": " << it.second << std::endl;
        }
        std::string body = "Hello Bite\n";
        body += "Hello World\n";
        rsp.set_content(body, "text/html");
        rsp.status = 200;
    });
    // 3. 启动服务器
    server.listen("0.0.0.0", 9090);
    return 0;
}